package net.maku.module.staff.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.maku.framework.common.utils.PageResult;
import net.maku.framework.common.utils.Result;
import net.maku.module.staff.convert.StaffConvert;
import net.maku.module.staff.entity.StaffEntity;
import net.maku.module.staff.service.StaffService;
import net.maku.newbase.NewBaseController;
import net.maku.newbase.NewQuery;
import net.maku.newbase.PageParam;
import net.maku.newbase.R;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 业务_员工
 *
 * @author
 */
@RestController
@RequestMapping("nb/staff")
@Tag(name = "业务_员工")
@AllArgsConstructor
public class StaffController extends NewBaseController<StaffService, StaffEntity> {

    /**
     * 分页查询
     *
     * @param page
     * @param query
     * @return
     */
    @Operation(summary = "分页")
    @RequestMapping(value = "/page", method = RequestMethod.GET)
    public Result page(PageParam page, NewQuery query) {
        LambdaQueryWrapper<StaffEntity> select = new LambdaQueryWrapper<>();

        IPage<StaffEntity> iPage = entityService.page(page.b(), select);
        return Result.ok(new PageResult<>(StaffConvert.INSTANCE.convertList(iPage.getRecords()), iPage.getTotal()));
    }

    /**
     * 删除
     *
     * @param idList
     * @return
     */
    @DeleteMapping
    @Operation(summary = "删除")
    public R delete(@RequestBody List<Long> idList) {
        return R.ok(entityService.removeByIds(idList));
    }

}